from selenium import webdriver
from .login import login_test
from time import sleep
from ..lib.screenshot_function import screenshot
from selenium.webdriver.chrome.options import Options


def open_browser(browser_name, url):
    driver = None
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--window-size=1920,1080')
    if browser_name == "chrome":
        driver = webdriver.Chrome(chrome_options=chrome_options)
    if browser_name == "ff":
        driver = webdriver.Firefox()
    if browser_name == "ie":
        driver = webdriver.Ie()
    driver.maximize_window()
    driver.implicitly_wait(10)
    driver.get(url)
    return driver


class TestKeys(object):

    def __init__(self, browser_name, url, username, password, new_password):
        self.driver = open_browser(browser_name, url)
        self.username = username
        self.password = password
        self.new_password = new_password

    def webui1(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 检查项管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[2]').click()
        sleep(1)
        returns_list = []
        for dicts in list_dicts:
            if dicts["check_number"] and dicts["check_name"] and dicts["module_name"]:
                # 检查项编号
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(
                    dicts["check_number"])
                sleep(1)
                # 操作系统-筛选条件-检查项名称
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[2]/div/div/div/input').send_keys(
                    dicts["check_name"])
                sleep(1)
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[3]/div/div/div/div/input').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["check_number"] is not None:
                # 检查项编号
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(
                    dicts["check_number"])
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["check_name"] is not None:
                # 操作系统-筛选条件-检查项名称
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[2]/div/div/div/input').send_keys(
                    dicts["check_name"])
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["module_name"] is not None:
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[3]/div/div/div/div/input').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[2]/main/div/div[3]/table/tbody/tr[1]/td[2]/div').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
        #
        # # 数据库
        # driver.find_element_by_xpath('//*[@id="tab-2"]').click()
        # sleep(1)
        # # 数据库-筛选条件-检查项名称
        # driver.find_element_by_xpath('//*[@id="pane-2"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys("禁止以管理员帐号权限运行oracle")
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-2"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-2"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(2)
        # # 组件名称-SQL_Server
        # driver.find_element_by_xpath('//*[@id="pane-2"]/div[1]/main/div/main/form/div/div[2]/div/div/div/div[1]/span/span').click()
        # sleep(1)
        # driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-2"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-2"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(3)
        #
        # # 中间件
        # driver.find_element_by_xpath('//*[@id="tab-3"]').click()
        # sleep(1)
        # # 中间件-筛选条件-检查项名称
        # driver.find_element_by_xpath('//*[@id="pane-3"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys("检查weblogic账户锁定重置持续时间")
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-3"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-3"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(2)
        # # 组件名称-WebLogic
        # driver.find_element_by_xpath('//*[@id="pane-3"]/div[1]/main/div/main/form/div/div[2]/div/div/div/div[1]/span/span').click()
        # sleep(1)
        # driver.find_element_by_xpath('/html/body/div[7]/div[1]/div[1]/ul/li[1]').click()
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-3"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-3"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(3)
        #
        # # 安全设备
        # driver.find_element_by_xpath('//*[@id="tab-4"]').click()
        # sleep(1)
        # # 安全设备-筛选条件-检查项名称
        # driver.find_element_by_xpath('//*[@id="pane-4"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys("访问规则应按照一定的规则进行分组")
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-4"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-4"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(2)
        # # 组件名称-WebLogic
        # driver.find_element_by_xpath('//*[@id="pane-4"]/div[1]/main/div/main/form/div/div[2]/div/div/div/div[1]/span/span').click()
        # sleep(1)
        # driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[1]/ul/li[1]').click()
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-4"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-4"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(3)
        #
        # # 网络设备
        # driver.find_element_by_xpath('//*[@id="tab-5"]').click()
        # sleep(1)
        # # 网络设备-筛选条件-检查项名称
        # driver.find_element_by_xpath('//*[@id="pane-5"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys("检查思科路由器是否删除无用账户")
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-5"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-5"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(2)
        # # 组件名称-WebLogic
        # driver.find_element_by_xpath('//*[@id="pane-5"]/div[1]/main/div/main/form/div/div[2]/div/div/div/div[1]/span/span').click()
        # sleep(1)
        # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
        # sleep(1)
        # # 查询
        # driver.find_element_by_xpath('//*[@id="pane-5"]/div[1]/main/div/main/form/div/button[1]').click()
        # sleep(2)
        # # 重置
        # driver.find_element_by_xpath('//*[@id="pane-5"]/div[1]/main/div/main/form/div/button[2]').click()
        # sleep(3)
        print(returns_list)
        return returns_list

    def webui2(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 检查项管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[2]').click()
        returns_list = []
        for dicts in list_dicts:
            # 新增
            driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/header/div[2]/button').click()
            sleep(1)
            # 新增模板
            if dicts["check_number"] is not None:
                # 编号
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').send_keys(
                    dicts["check_number"])
                sleep(1)
            if dicts["risk_level"] is not None:
                # 风险等级-低
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div/input').click()
                sleep(1)
                if dicts["check_number"] is None:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                # elif dicts["check_number"] and dicts["os"] and dicts["module_name"] and dicts["source"] and dicts["check_name"] is not None:
                #     driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[1]/ul/li[1]').click()
                #     sleep(1)
                elif dicts["check_number"] == dicts["check_number_2"]:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
            if dicts["os"] is not None:
                # 系统类型-linux
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/input').click()
                sleep(1)
                if dicts["check_number"] is None:
                    driver.find_element_by_xpath('/html/body/div[7]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                elif dicts["check_number"] == dicts["check_number_2"]:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                elif dicts["risk_level"] is None:
                    driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
            if dicts["module_name"] is not None:
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/input').click()
                sleep(1)
                if dicts["check_number"] is None:
                    driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                elif dicts["check_number"] == dicts["check_number_2"]:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                elif dicts["risk_level"] is None:
                    driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
            # /html/body/div[5]/div[1]/div[1]/ul/li[1]
            # # 基线编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/input').send_keys("操作系统测试-001")
            # sleep(1)
            # 来源
            if dicts["source"] is not None:
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div/div/input').click()
                sleep(1)
                if dicts["check_number"] is None:
                    driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                elif dicts["check_number"] == dicts["check_number_2"]:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                elif dicts["risk_level"] is None:
                    driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                elif dicts["module_name"] is None:
                    driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
            if dicts["check_name"] is not None:
                # 检查项名称
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div[1]/input').send_keys(
                    dicts["check_name"])
                sleep(1)
            # 检测方法
            driver.find_element_by_xpath(
                '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div/textarea').send_keys(
                "操作系统测试-001")
            sleep(1)
            # 保存
            driver.find_element_by_xpath(
                '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/div/button[2]').click()
            sleep(3)
            #
            # # 数据库
            # driver.find_element_by_xpath('//*[@id="tab-2"]').click()
            # sleep(1)
            # # 新增
            # driver.find_element_by_xpath('//*[@id="pane-2"]/div[2]/header/div[2]/button').click()
            # sleep(1)
            # # 新增模板
            # # 编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').send_keys("000001")
            # sleep(1)
            # # 系统类型-linux
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 组件名称-SQL_Server
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 风险等级-中
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
            # sleep(1)
            # # 基线编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/input').send_keys("数据库测试-001")
            # sleep(1)
            # # 来源
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 基线检查项
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div[1]/input').send_keys("数据库测试-001")
            # sleep(1)
            # # 检测方法
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[6]/div/div/div/div/textarea').send_keys("数据库测试-001")
            # sleep(1)
            # # 保存
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/div/button[2]').click()
            # sleep(3)
            #
            # # 中间件
            # driver.find_element_by_xpath('//*[@id="tab-3"]').click()
            # sleep(1)
            # # 新增
            # driver.find_element_by_xpath('//*[@id="pane-3"]/div[2]/header/div[2]/button').click()
            # sleep(1)
            # # 新增模板
            # # 编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').send_keys("000001")
            # sleep(1)
            # # 系统类型-linux
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 组件名称-WebLogic
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 风险等级-中
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
            # sleep(1)
            # # 基线编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/input').send_keys("中间件测试-001")
            # sleep(1)
            # # 来源
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 基线检查项
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div[1]/input').send_keys("中间件测试-001")
            # sleep(1)
            # # 检测方法
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[6]/div/div/div/div/textarea').send_keys("中间件测试-001")
            # sleep(1)
            # # 保存
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/div/button[2]').click()
            # sleep(3)
            #
            # # 安全设备
            # driver.find_element_by_xpath('//*[@id="tab-4"]').click()
            # sleep(1)
            # # 新增
            # driver.find_element_by_xpath('//*[@id="pane-4"]/div[2]/header/div[2]/button').click()
            # sleep(1)
            # # 新增模板
            # # 编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').send_keys("000001")
            # sleep(1)
            # # 系统类型-linux
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 组件名称-Cisco
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 风险等级-中
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
            # sleep(1)
            # # 基线编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/input').send_keys("安全设备测试-001")
            # sleep(1)
            # # 来源
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 基线检查项
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div[1]/input').send_keys("安全设备测试-001")
            # sleep(1)
            # # 检测方法
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[6]/div/div/div/div/textarea').send_keys("安全设备测试-001")
            # sleep(1)
            # # 保存
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/div/button[2]').click()
            # sleep(3)
            #
            # # 网络设备
            # driver.find_element_by_xpath('//*[@id="tab-5"]').click()
            # sleep(1)
            # # 新增
            # driver.find_element_by_xpath('//*[@id="pane-5"]/div[2]/header/div[2]/button').click()
            # sleep(1)
            # # 新增模板
            # # 编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').send_keys("000001")
            # sleep(1)
            # # 系统类型-linux
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 组件名称-Cisco
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 风险等级-中
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
            # sleep(1)
            # # 基线编号
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/input').send_keys("网络设备测试-001")
            # sleep(1)
            # # 来源
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[1]').click()
            # sleep(1)
            # # 基线检查项
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div[1]/input').send_keys("网络设备测试-001")
            # sleep(1)
            # # 检测方法
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[6]/div/div/div/div/textarea').send_keys("网络设备测试-001")
            # sleep(1)
            # # 保存
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/div/button[2]').click()
            # sleep(3)
            if dicts["check_number"] and dicts["check_number_2"] is not None:
                alert_text = driver.find_element_by_xpath('/html/body/div[7]/p').text
                print(alert_text)
                returns_list.append(alert_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["check_number"] is None:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["risk_level"] is None:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["os"] is None:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["module_name"] is None:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["source"] is None:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["check_name"] is None:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if len(dicts["check_number"]) > 16:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if len(dicts["check_name"]) > 200:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            # 检查项编号
            driver.find_element_by_xpath(
                '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(
                dicts["check_number"])
            # 查询
            sleep(5)
            driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
            sleep(2)
            returns_list.append("新增成功")
        print(returns_list)
        return returns_list

    def webui3(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 检查项管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[2]').click()
        sleep(1)
        returns_list = []
        for dicts in list_dicts:
            if dicts["check_number"] and dicts["check_name"] and dicts["module_name"]:
                # 检查项编号
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(
                    dicts["check_number"])
                sleep(1)
                # 操作系统-筛选条件-检查项名称
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[2]/div/div/div/input').send_keys(
                    dicts["check_name"])
                sleep(1)
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[3]/div/div/div/div/input').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[1]').click()
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                # 编辑
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/table/tbody/tr/td[7]/div/button[1]').click()
                sleep(1)
                # 新增模板
                if dicts["check_number"] is not None:
                    # 编号
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').clear()
                    driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[1]/div/div/div/input').send_keys(
                        dicts["check_number_2"])
                    sleep(1)
                if dicts["risk_level"] is not None:
                    # 风险等级-低
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div/input').click()
                    sleep(1)
                    if dicts["check_number"] is None:
                        driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
                        sleep(1)
                    # elif dicts["check_number"] and dicts["os"] and dicts["module_name"] and dicts["source"] and dicts["check_name"] is not None:
                    #     driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[1]/ul/li[1]').click()
                    #     sleep(1)
                    else:
                        driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[1]/ul/li[2]').click()
                        sleep(1)
                if dicts["os"] is not None:
                    # 系统类型-linux
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/input').click()
                    sleep(1)
                    if dicts["check_number"] is None:
                        driver.find_element_by_xpath('/html/body/div[7]/div[1]/div[1]/ul/li[1]').click()
                        sleep(1)
                    elif dicts["risk_level"] is None:
                        driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[1]/ul/li[1]').click()
                        sleep(1)
                    else:
                        driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
                        sleep(1)
                if dicts["module_name"] is not None:
                    # 组件名称-centos6
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/input').click()
                    sleep(1)
                    if dicts["check_number"] is None:
                        driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[1]/ul/li[1]').click()
                        sleep(1)
                    elif dicts["risk_level"] is None:
                        driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[1]/ul/li[1]').click()
                        sleep(1)
                    else:
                        driver.find_element_by_xpath('/html/body/div[10]/div[1]/div[1]/ul/li[1]').click()
                        sleep(1)
                # /html/body/div[5]/div[1]/div[1]/ul/li[1]
                # # 基线编号
                # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/input').send_keys("操作系统测试-001")
                # sleep(1)
                # 来源
                if dicts["source"] is not None:
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[3]/div/div/div/div/div/input').click()
                    sleep(1)
                    if dicts["check_number"] is None:
                        driver.find_element_by_xpath('/html/body/div[9]/div[1]/div[1]/ul/li[2]').click()
                        sleep(1)
                    elif dicts["risk_level"] is None:
                        driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[2]').click()
                        sleep(1)
                    elif dicts["module_name"] is None:
                        driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[2]').click()
                        sleep(1)
                    else:
                        driver.find_element_by_xpath('/html/body/div[11]/div[1]/div[1]/ul/li[4]').click()
                        sleep(1)
                if dicts["check_name"] is not None:
                    # 检查项名称
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div[1]/input').clear()
                    driver.find_element_by_xpath(
                        '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[4]/div/div/div/div[1]/input').send_keys(
                        dicts["check_name_2"])
                    sleep(1)
                # 检测方法
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div/textarea').clear()
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/form/div[5]/div/div/div/div/textarea').send_keys(
                    "操作系统测试-001PUT")
                sleep(1)
                # 保存
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/div/div[2]/div/button[2]').click()
                sleep(3)
                driver.refresh()
                sleep(2)
                # 检查项编号
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(dicts["check_number_2"])
                sleep(1)
                # 检查项名称
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[2]/div/div/div/input').send_keys(
                    dicts["check_name_2"])
                sleep(1)
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[3]/div/div/div/div/input').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[5]').click()
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "共 1 条":
                    returns_list.append("编辑成功")
                else:
                    returns_list.append("编辑失败")
                # 重置
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[2]').click()
                sleep(1)
                continue
        print(returns_list)
        return returns_list

    def webui4(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 检查项管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[2]').click()
        sleep(2)
        returns_list = []
        for dicts in list_dicts:
            if dicts["check_number"] and dicts["check_name"] and dicts["module_name"] is not None:
                # 检查项编号
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(
                    dicts["check_number"])
                sleep(1)
                # 操作系统-筛选条件-检查项名称
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[2]/div/div/div/input').send_keys(
                    dicts["check_name"])
                sleep(1)
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[3]/div/div/div/div/input').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[5]').click()
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                # 删除
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/table/tbody/tr/td[7]/div/button[2]').click()
                sleep(1)
                # 确定
                driver.find_element_by_xpath('/html/body/div[7]/div/div[3]/button[2]').click()
                sleep(1)
                # 重置
                # driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[2]').click()
                driver.refresh()
                sleep(2)
                # 检查项编号
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[1]/div/div/div/input').send_keys(
                    dicts["check_number"])
                sleep(1)
                # 操作系统-筛选条件-检查项名称
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[2]/div/div/div/input').send_keys(
                    dicts["check_name"])
                sleep(1)
                # 组件名称-centos6
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[3]/div/div/div/div/input').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[5]').click()
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath('//*[@id="pane-1"]/div[2]/main/div/div[3]/div/span').text
                print(error_text)
                if error_text == "暂无数据":
                    returns_list.append("删除成功")
                else:
                    returns_list.append("删除失败")
                # 重置
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div[1]/main/div/main/form/div/div[4]/button[2]').click()
                sleep(1)
                continue
        print(returns_list)
        return returns_list

    def quit(self):
        """
        浏览器退出
        :return:
        """
        self.driver.quit()
